package com.hunliji.monitor.web.controller.app;

import com.hunliji.common.response.PageData;
import com.hunliji.common.response.ResponseData;
import com.hunliji.monitor.service.api.model.param.OperateAffirmOrderParam;
import com.hunliji.monitor.service.api.model.param.QueryAffirmOrderParam;
import com.hunliji.monitor.web.filter.GeneralContext;
import com.hunliji.monitor.share.enums.order.AffirmStatusEnum;
import com.hunliji.monitor.web.facade.TableAffirmOrderFacade;
import com.hunliji.monitor.web.filter.auth.NeedAuth;
import com.hunliji.monitor.web.model.vo.AffirmOrderVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 确认单有关
 * @author wuchen
 */
@RestController
@RequestMapping("/tableAffirmOrder")
public class TableAffirmOrderController {
    @Resource
    private TableAffirmOrderFacade tableAffirmOrderFacade;

    /**
     * 查询列表
     * @param queryAffirmOrderParam
     * @return
     */
    @PostMapping("/queryPage")
    @NeedAuth
    public ResponseData<PageData<AffirmOrderVO>> queryPage(@RequestBody QueryAffirmOrderParam queryAffirmOrderParam){
        Long userId = GeneralContext.getAdmin().getId();
        queryAffirmOrderParam.setUserId(userId);
        return ResponseData.success(tableAffirmOrderFacade.queryPage(queryAffirmOrderParam));
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @NeedAuth
    @GetMapping("/queryById")
    public ResponseData<AffirmOrderVO> queryById(@RequestParam("id") Long id){
        Long userId = GeneralContext.getAdmin().getId();
        return ResponseData.success(tableAffirmOrderFacade.queryById(id,userId));
    }

    /**
     * 通过确认单
     * @param operateAffirmOrderParam
     * @return
     */
    @NeedAuth
    @PostMapping("/pass")
    public ResponseData pass(@RequestBody OperateAffirmOrderParam operateAffirmOrderParam){
        operateAffirmOrderParam.setAffirmStatus(AffirmStatusEnum.PASS.getCode());
        tableAffirmOrderFacade.operateStatus(operateAffirmOrderParam,GeneralContext.getAdmin().getId());
        return ResponseData.success(null);
    }

    /**
     * 驳回确认单
     * @param operateAffirmOrderParam
     * @return
     */
    @NeedAuth
    @PostMapping("/reject")
    public ResponseData reject(@RequestBody OperateAffirmOrderParam operateAffirmOrderParam){
        operateAffirmOrderParam.setAffirmStatus(AffirmStatusEnum.REJECT.getCode());
        tableAffirmOrderFacade.operateStatus(operateAffirmOrderParam,GeneralContext.getAdmin().getId());
        return ResponseData.success(null);
    }
}
